home *** CD-ROM | disk | FTP | other *** search
- unit KeyText;
-
- // Splat.
- // Convert a virtual key code to a string.
- // Copyright ⌐ 2000 Tempest Software, Inc.
-
- interface
-
- uses Windows, SysUtils, Menus;
-
- function KeyCodeToText(KeyCode: Word): string;
- function KeyCodeToDisplay(KeyCode: Word): WideString;
-
- implementation
-
- // Convert a virtual key code to a file or resource name.
- function KeyCodeToText(KeyCode: Word): string;
- begin
- case KeyCode of
- Ord('0')..Ord('9'):
- Result := 'Digit' + Chr(KeyCode);
- Ord('A')..Ord('Z'):
- Result := Chr(KeyCode);
- Vk_NumPad0..Vk_NumPad9:
- Result := 'NumPad' + Chr(Ord('0') + KeyCode - Vk_NumPad0);
- else
- Result := ShortCutToText(KeyCode);
- if (Result = '') or (Pos(' ', Result) > 0) or not (Result[1] in ['a'..'z','A'..'Z']) then
- Result := Format('Char%.2X', [KeyCode]);
- end;
- end;
-
- // Convert a virtual key code to a user-friendly character or key name.
- function KeyCodeToDisplay(KeyCode: Word): WideString;
- var
- KeyState: TKeyboardState;
- Text: array[0..3] of WideChar;
- begin
- GetKeyboardState(KeyState);
- FillChar(Text, SizeOf(Text), 0);
- if ToUnicode(KeyCode, 0, KeyState, Text, SizeOf(Text) div SizeOf(WideChar), 0) > 0 then
- Result := Text
- else
- begin
- Result := KeyCodeToText(KeyCode);
- if (Length(Result) = 6) and (Copy(Result, 1, 4) = 'Char') then
- Result := Result + ' (' + ShortCutToText(KeyCode) + ')';
- end;
- end;
-
- end.
-